package com.jiangman.weather.adapter;

/**
 * Created by secoro on 2017/4/26.
 */

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.jiangman.weather.R;
import com.jiangman.weather.bean.WeatherZhiShu;

import java.util.ArrayList;

/**
 * 生活指数适配器
 */
public class MyLivingIndexBaseAdapter extends BaseAdapter {
    Activity mActivity;
    private ArrayList<WeatherZhiShu> mZhishuList;
    /**
     * 用于存放生活指数对应的icon的集合
     */
    private ArrayList<Integer> resIdList;

    public MyLivingIndexBaseAdapter(Activity mActivity, ArrayList<WeatherZhiShu> mZhishuList, ArrayList<Integer> resIdList) {
        this.mActivity = mActivity;
        this.mZhishuList = mZhishuList;
        this.resIdList = resIdList;
    }

    @Override
    public int getCount() {
        return mZhishuList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view;
        LivingIndexViewHolder livingIndexViewHolder;
        if (convertView == null) {
            view = View.inflate(mActivity, R.layout.item_living_index_simple, null);
            livingIndexViewHolder = new LivingIndexViewHolder();
            livingIndexViewHolder.tv_name = (TextView) view.findViewById(R.id.tv_name);
            livingIndexViewHolder.tv_value = (TextView) view.findViewById(R.id.tv_value);
            livingIndexViewHolder.iv_icon = (ImageView) view.findViewById(R.id.iv_icon);
            view.setTag(livingIndexViewHolder);
        } else {
            view = convertView;
            livingIndexViewHolder = (LivingIndexViewHolder) view.getTag();
        }
        livingIndexViewHolder.tv_name.setText(mZhishuList.get(position).getName());
        livingIndexViewHolder.tv_value.setText(mZhishuList.get(position).getValue());
        livingIndexViewHolder.iv_icon.setImageResource(resIdList.get(position));
        return view;
    }

    static class LivingIndexViewHolder {
        TextView tv_name;
        TextView tv_value;
        ImageView iv_icon;
    }
}
